import requests
import os

def download_video(url, save_path=None):
    # 如果没有传入保存路径，默认保存到当前目录
    if save_path is None:
        save_path = os.path.basename(url)
    
    # 发送GET请求下载文件
    try:
        response = requests.get(url, stream=True)
        response.raise_for_status()  # 确保请求成功

        # 打开本地文件写入数据
        with open(save_path, 'wb') as file:
            for chunk in response.iter_content(chunk_size=8192):  # 分块下载，减少内存占用
                file.write(chunk)
        
        print(f"视频已下载至: {save_path}")
    except requests.exceptions.RequestException as e:
        print(f"下载失败: {e}")

if __name__ == "__main__":
    video_url = "https://video.openersal.com/d05152c4e45f71efbfa8640086ac0102/a2295e9f7577444f8892fe414a30da3d-85ecf26bd92352ebd735fb03a6e8d799-od-S00000001-200000.mp4"
    download_video(video_url)
